package com.time.client.application.converter;

import com.time.client.application.dto.CommentDTO;
import com.time.client.common.entity.PageResult;
import com.time.client.domain.entity.CommentBO;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;

import java.util.List;

/**
 * 评论DTO转换类
 *
 * @author: HuangQi
 * @date: Created in 10:50 2025/11/3
 * @description: 评论DTO转换类
 */
@Mapper
public interface CommentDTOConverter {

    CommentDTOConverter INSTANCE = Mappers.getMapper(CommentDTOConverter.class);

    CommentBO convertDTOToBO(CommentDTO commentDTO);

    List<CommentDTO> convertBOListToDTO(List<CommentBO> commentBOList);

    default PageResult<CommentDTO> convertBOPageToDTOPage(PageResult<CommentBO> boPage) {
        PageResult<CommentDTO> dtoPage = new PageResult<>();
        if (boPage == null) {
            return dtoPage;
        }
        dtoPage.setPageNo(boPage.getPageNo());
        dtoPage.setPageSize(boPage.getPageSize());
        dtoPage.setTotal(boPage.getTotal());
        dtoPage.setTotalPage(boPage.getTotalPage());
        dtoPage.setStart(boPage.getStart());
        dtoPage.setEnd(boPage.getEnd());
        if (boPage.getResult() != null && !boPage.getResult().isEmpty()) {
            List<CommentDTO> dtoList = convertBOListToDTO(boPage.getResult());
            dtoPage.setResult(dtoList);
        }
        return dtoPage;
    }
}
